import { makeAutoObservable } from "mobx"

class TestStore {
  num = 0
  constructor() {
    makeAutoObservable(this)
  }
  arr = []
  change = num => {
    this.num = num;
  }
  clearNum = () => {
    this.num = 0
  }
  add = () => {
    this.num++
    this.arr.push(12)
    this.arr = [...this.arr]
  }
  sub = () => {
    this.num--
  }
  breadcrumbArr = ['home', 'option']
  setBreadcrumbArr = (item) => {
    if (this.breadcrumbArr.length === 0) {
      this.breadcrumbArr.push(item)
      this.breadcrumbArr = [...this.breadcrumbArr]
      return
    }
    if (this.breadcrumbArr.length > 0) {
      let index = this.breadcrumbArr.indexOf(item)
      if (index != -1) {
        let arr = this.breadcrumbArr.slice(0, index + 1)
        this.breadcrumbArr = arr
      } else {
        this.breadcrumbArr.push(item)
        this.breadcrumbArr = [...this.breadcrumbArr]
      }
    }
  }
  setBreadcrumb = (arr) => {
    this.breadcrumbArr = arr
  }
}

export default TestStore